home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
UTIL
/
Acme Filters 2.3.2 folder.sit
/
Acme Filters 2.3.2 folder
/
Acme Filters 2.3.2
/
Acme Filters オ
/
Sources
/
Tab2Space.c
< prev
next >
Wrap
Text File
|
1996-03-02
|
2KB
|
82 lines
/************ I N C L U D E F I L E S *******************************************************/
#include <stdio.h>
#include "Acme Filters.h"
#include "Tab2Space.h"
/**********************************************************************************************
* Function Name: Tab2Space
*
* Description: Convert tabs to equivalent spaces.
*
* Parameters: iFile - file spec of a file.
*
* Return Value: None.
**********************************************************************************************/
void Tab2Space( FSSpec *iFile )
{
FILE *iFp, *oFp;
char iBuf[kBufSize];
char *c;
FSSpec oFile;
FInfo iInfo, oInfo;
short pad, col = 0;
// create and open the output file
FSMakeFSSpec( iFile->vRefNum, iFile->parID, iFile->name, &oFile );
pstrcpy( oFile.name, kTempFileName ); // use a temporary name
oFp = FSpfopen( &oFile, "wb" );
// set the output file's type and creator
FSpGetFInfo( iFile, &iInfo );
FSpGetFInfo( &oFile, &oInfo );
oInfo.fdType = iInfo.fdType;
oInfo.fdCreator = iInfo.fdCreator;
FSpSetFInfo( &oFile, &oInfo );
// filter the input file
if ( iFp = FSpfopen( iFile, "rb" ) )
{
while ( fgets( iBuf, kBufSize-1, iFp ) != nil )
{
gCancelReq |= Cancel();
ScrollIcon();
c = iBuf;
while ( *c )
{
if ( *c == kTab ) // replace tabs with spaces
{
pad = kTabSize - ( col % kTabSize );
while ( pad-- )
{
fputc( kSpace, oFp );
col++;
}
}
else // let everything else go unchanged
{
fputc( *c, oFp );
col++;
}
if ( *c == kCR ) col = 0;
c++;
}
}
}
// close the files
if ( iFp ) fclose( iFp );
if ( oFp ) fclose( oFp );
// swap the contents of the two files and delete the copy
FSpExchangeFiles( &oFile, iFile );
FSpDelete( &oFile );
TickleParentDir( &oFile );
}